<?php include_once 'Pecahan/sessionLontong.php'; ?>
<?php
if (isset($_GET['name_viewed'])!= NULL) {
    $name_viewed = $_GET['name_viewed'];
}
else if (isset($_SESSION['user_name'])!= NULL) {
    $name_viewed = $_SESSION['user_name'];
}
if (isset($_SESSION['user_name'])!= NULL) {
    $name_logon = $_SESSION['user_name'];
    $temp = new login();
    $role = $temp->getRole($name_logon );
}
else {
    $name_logon = NULL;
    $role = NULL;
}
?>
<?php
include_once 'controller/message.php';
include_once 'controller/login.php';
include_once 'controller/follow.php';

if (isset($_GET['fol'])!= NULL) {
    $doFoll = new follow();
    if($_GET['fol'] == 'yes') {
        $doFoll->addFollowing($name_logon, $name_viewed);
    }
    else if ($_GET['fol'] == 'no') {
        $doFoll->deleteFollowing($name_logon, $name_viewed);
    }
}
if(isset ($_POST['sendmessageButton'])) {
    $cekSaja = new login();
    $sentMessage = new message();
    $valid = true;
    $target = $sentMessage->parsing($_POST['touser']);
    foreach($target as $i) {
        if ($cekSaja->isUserExist($i)) {
            $valid = $valid && true;
        }else {
            $valid = $valid && false;
        }
    }
    if ($valid) {
        // sent message
        $sentMessage->sentMsg($name_logon, $_POST['touser'], $_POST['subject'], $_POST['bodymessage'],$_GET['replyOfMsgID']);
        $boolean_sent = 1;
    }
    else {
        $boolean_sent = 2;
    }

}
else
    $boolean_sent = 0;

?>
<?php $judul = 'Konfirmasi Pesan'; ?>
<?php include_once 'Pecahan/header.php'; ?>

<div id ="content" class="isipage">
    <div class="isipagecenter">
        <?php
        if ($boolean_sent == 1) {
            echo'<div class="paddcongrat"><label id="titlebold">Congratulations</label></div>';
            echo'<div><label id="bold">Your message has been sent</label></div>';
        }
        else {
            echo'<div class="paddcongrat"><label id="titlebold">Sending Failed</label></div>';
            echo'<div><label id="bold">Your message failed to sent</label></div>';
        }
        ?>
    </div>
</div>
<?php include_once 'Chat/chat.php';?>
<?php include_once 'Pecahan/footer.php'; ?>
